package org.arabidopsis.plantCyc;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.NoSuchElementException;

import org.biojava.bio.BioException;
import org.biojavax.Namespace;
import org.biojavax.RichObjectFactory;
import org.biojavax.bio.seq.RichSequence;
import org.biojavax.bio.seq.RichSequenceIterator;

public class ParseFasta {
	public static RichSequenceIterator getOneSequence(String fastaFileName) {
		
		// an input Fasta file
		try {
		BufferedReader br;
			br = new BufferedReader(new FileReader(fastaFileName));
		// a namespace to override that in the file
		Namespace ns = RichObjectFactory.getDefaultNamespace();                   
		// we are reading DNA sequences
		RichSequenceIterator seqs = RichSequence.IOTools.readFastaProtein(br,ns);   
		while (seqs.hasNext()) {
		    RichSequence rs;
			rs = seqs.nextRichSequence();
		    // write it in EMBL format to standard out
		    //RichSequence.IOTools.writeFasta(System.out, rs, ns);
			System.out.println(rs.getAccession()+ " " + rs.getDescription());
			System.out.println(rs.seqString());
		}
		}catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		catch (NoSuchElementException e){ 
			e.printStackTrace();
		} catch (BioException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}   
		}

	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {

}
